package com.a0soft.gphone.aTruffleHog.di;
/*
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 3, or (at your option) any
 * later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * Copyright(C) 2011 
 *   Sam Lu <ysl.sam.lu (at) gmail.com>
 *
 */

import com.a0soft.gphone.aTruffleHog.util.CONSTS;
import com.a0soft.gphone.aTruffleHog.util.MiscUtil;

import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.telephony.TelephonyManager;
import android.text.TextUtils;

class TeleInfo extends BaseInfo {    
    //private static final String LOG_TAG = TeleInfo.class.getSimpleName();
    
    static void
    Build(DeviceInfo di)
    {
        Context ctx = MiscUtil.GetAppContext();
        TelephonyManager mgr = (TelephonyManager)ctx.getSystemService(Context.TELEPHONY_SERVICE);
        Configuration cfg = Resources.getSystem().getConfiguration();
        
        int nPhoneType = TelephonyManager.PHONE_TYPE_NONE;
        try {
            nPhoneType = mgr.getPhoneType();
        } catch (Exception e) {
        }
        
        di.Put(DeviceInfoKey.K.TP_TYPE, nPhoneType);
        di.Put(DeviceInfoKey.K.TP_SIM_MCC, cfg.mcc);
        di.Put(DeviceInfoKey.K.TP_SIM_MNC, cfg.mnc);
        di.Put(DeviceInfoKey.K.TP_SIM_COUNTRY, mgr.getSimCountryIso().toLowerCase());
        
        String str;
        try { 
            str = mgr.getSimOperatorName();  //need READ_PHONE_STATE
        } catch (Exception e) {
            str = null;
        }
        
        if (TextUtils.isEmpty(str)) str = CONSTS.UNAVAILABLE;
        di.Put(DeviceInfoKey.K.TP_OP_NAME, str);
        
        try {
            str = mgr.getDeviceSoftwareVersion(); //need READ_PHONE_STATE
        } catch (Exception e) {
            str = null;
        }
        
        if (TextUtils.isEmpty(str)) str = CONSTS.UNAVAILABLE;
        di.Put(DeviceInfoKey.K.TP_VERSION, str);
    }	
}
